package org.pliers.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.pliers.LbIsolationContextHolder;
import org.pliers.service.ConfigInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class ConfigClientController {

    private static final Logger log = LoggerFactory.getLogger(ConfigClientController.class);
    @Autowired
    private ConfigInfoService service ;

    @GetMapping("/configInfo")
    @SentinelResource(value = "configInfo1",  blockHandler = "blockHandler" )
    public String  getConfigInfo(String id) throws Exception {
        log.info("version:"+LbIsolationContextHolder.getVersion() );
        return service.getConfigInfo(id) ;
    }

    public String blockHandler (String id , BlockException e) {
        return "controller block:"+id;
    }
}
